package diningTest;

import javax.swing.*;
import java.util.Date;

public class Test {
    public static String[] idArr = {"zhangsan", "lisi"};
    public static String[] passwordArr = {"123", "456"};

    public static double[] accountdArr = {500, 1000}; // 余额
    public static double[] totalArr = {100, 200}; // 累计消费

    public static int userIndex = -1; // 假设登录成功的用户下标

    public static String[] logArr = new String[5]; // 保存操作的日志数组

    public static void main(String[] args) {
        // 登录成功
        userIndex = 1; // 李四登录成功
        while (true) {

            String opt = JOptionPane.showInputDialog(null, "1. 充值 \n 2. 消费 \n 3. 余额查询 \n 4. 交易记录 5. 修改 \n 6. 退出");
            if (opt == null) {
                return;
            }
            switch (opt) {
                case "1": // 充值
                    addMoney();
                    break;
                case "2": // 消费

                    break;
                case "3": // 余额查询
                    JOptionPane.showMessageDialog(null, "卡上余额：" + accountdArr[userIndex] + "\n 累计消费：" + totalArr[userIndex]);
                    break;
                case "4": // 交易记录
                    queryHistory();
                    break;
                case "5":
                    break;
                case "6":
                    break;
            }
        }
    }

    // 交易记录
    public static void queryHistory() {
        String str = "交易信息     日期 \n";
        for (int i = 0; i < logArr.length; i++) {
            if (logArr[i] != null) {
                str += logArr[i] + "\n";
            }
        }
        JOptionPane.showMessageDialog(null, str);
    }

    // 获取日期时间
    public static String getDate() {
        Date date = new Date();
        int year = date.getYear() + 1900;
        int month = date.getMonth() + 1;
        int day = date.getDate();
        return year + "-" + month + "-" + day;
    }


    // 充值
    public static void addMoney() {
        String value = JOptionPane.showInputDialog(null, "请输入充值金额");
        int money = Integer.parseInt(value);
        accountdArr[userIndex] += money; // 存入到余额
        JOptionPane.showMessageDialog(null, "存入" + money + "元，\n 余额：" + accountdArr[userIndex] + "元");

        String str = "充值" + money + "元    " + getDate();
        for (int i = 0; i < logArr.length; i++) {
            if (logArr[i] == null) {
                logArr[i] = str;
                break;
            }
        }

    }
}
